package com.tencent.wxcloudrun.controller.utils;

import com.tencent.wxcloudrun.exception.BaseErrorInfoInterface;
import com.tencent.wxcloudrun.exception.ExceptionEnum;
import lombok.Data;

@Data
public final class ResultResponse {
    /**
     * 响应代码
     */
    private Integer code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应结构
     */
    private Object data;

    /**
     * 是否显示响应信息
     */
    private boolean showTip = true;

    public ResultResponse() {
    }

    // 四个参数的构造函数
    public ResultResponse(BaseErrorInfoInterface errorInfo) {
        this.code = errorInfo.getResultCode();
        this.msg = errorInfo.getResultMsg();
    }

    /**
     * 失败
     */
    public static ResultResponse ok(Object data, boolean showTip) {
        ResultResponse rb = new ResultResponse(ExceptionEnum.SUCCESS);
        rb.setData(data);
        rb.setShowTip(showTip);
        return rb;
    }

    /**
     * 失败
     */
    public static ResultResponse ok(Object data, String msg) {
        ResultResponse rb = new ResultResponse(ExceptionEnum.SUCCESS);
        rb.setData(data);
        rb.setMsg(msg);
        return rb;
    }

    public static ResultResponse ok(String msg) {
        ResultResponse rb = new ResultResponse();
        rb.setMsg(msg);
        rb.setCode(200);
        return rb;
    }

    /**
     * 失败
     */
    public static ResultResponse error(String msg) {
        ResultResponse rb = new ResultResponse();
        rb.setCode(500);
        rb.setMsg(msg);
        rb.setData(null);
        return rb;
    }

    /**
     * 失败
     */
    public static ResultResponse error(Integer code,String msg) {
        ResultResponse rb = new ResultResponse();
        rb.setCode(code);
        rb.setMsg(msg);
        rb.setData(null);
        return rb;
    }

    /**
     * 失败
     */
    public static ResultResponse error(BaseErrorInfoInterface errorInfo) {
        ResultResponse rb = new ResultResponse(errorInfo);
        rb.setData(null);
        return rb;
    }
}
